﻿using System;

namespace Bing
{
    /// <summary>
    /// Contains parameters for a request to the MobileWeb <see cref="ApiHelper.SourceType"/> that indicate:
    /// </summary>
    public class MobileWebRequest: IBingRequest
    {

        /// <summary>
        /// Gets or sets the number of results to return per <see cref="MobileWebRequest"/>.
        /// </summary>
        /// <value>Specifies the number of results to return per <see cref="MobileWebRequest"/>.</value>
        /// <remarks>
        /// If the number of results per page requested in the <see cref="MobileWebRequest"/>.Count field is greater than the total number of results returned in the <see cref="MobileWebResponse"/>.Total field, the number of results per page will be equal to the total number of results. <br />
        /// The default value for Count is 10 (ten), and the maximum count value is 50. If a value greater than 50 is specified, an error is returned..<br />
        /// Search results are limited to the first 1,000 results. This means that the total of <see cref="MobileWebRequest"/>.Count plus <see cref="MobileWebRequest"/>.Offset should not be greater than 1,000.<br />
        /// </remarks>
        public UInt32 Count { get; set; }

        /// <summary>
        /// Gets or sets the offset requested, from zero, for the starting point of the result set to be returned for this <see cref="MobileWebRequest"/>.
        /// </summary>
        /// <value>Specifies the offset requested, from zero, for the starting point of the result set to be returned for this <see cref="MobileWebRequest"/>.</value>
        /// <remarks>
        /// The offset specifies the requested position in the result set for the response that is returned for this source.<br />
        /// Offset is typically used in conjunction with the Count property on the <see cref="MobileWebRequest"/> object, and the Total property on the <see cref="MobileWebResponse"/> object, to facilitate paging through long lists of results.<br />
        /// The default value for Offset is 0 (zero), and the maximum offset value is 1,000. If a value greater than 1,000 is specified, an error is returned.Search results are limited to the first 1,000 results. This means that the total of <see cref="MobileWebRequest.Count" /> plus <see cref="MobileWebRequest.Offset" /> should not be greater than 1,000.<br />
        /// </remarks>
        public UInt32 Offset { get; set; }

        // TODO: Documentation Error: http://msdn.microsoft.com/en-us/library/dd560914.aspx, there is no MobileWebSearchOption.
        /// <summary>
        ///  Specifies options for this <see cref="MobileWebRequest"/>.
        /// </summary>
        public ApiHelper.WebSearchOption[] Options { get; set; }


        /// <summary>
        /// Creates the query string for the API call.
        /// </summary>
        /// <returns>The query string to append to the call.</returns>
        public string ToQueryString()
        {
            string request = string.Format("&MobileWeb.Count={0}", Count);
            request += string.Format("&MobileWeb.Offset={0}", Offset);
            foreach (ApiHelper.WebSearchOption option in Options)
            {
                request += string.Format("&MobileWeb.Options={0}", Enum.GetName(typeof(ApiHelper.WebSearchOption), option));
            }
            return request;
        }
    }
}
